﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sys.Controls
{
    public class OptIcons : WebControl
    {
        protected override void Render(HtmlTextWriter wt)
        {
            wt.Write(CreateHtml());
        }

        public string id { get; set; }

        public string CreateHtml()
        {
            string fipath = HttpContext.Current.Server.MapPath("~/public/easyui/themes/myicons");

            DirectoryInfo di = new DirectoryInfo(fipath);
            FileInfo[] flist = di.GetFiles();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<span class='list-span icon-add' value='icon-add'></span>");
            sb.AppendLine("<span class='list-span icon-edit' value='icon-edit'></span>");
            sb.AppendLine("<span class='list-span icon-remove' value='icon-remove'></span>");

            foreach (FileInfo item in flist)
            {
                string name = "icon-" + item.Name.Replace(item.Extension, string.Empty);
                sb.AppendLine("<span class='list-span " + name + "' value='" + name + "'></span>");
            }

            sb.AppendLine("<span class='list-span icon-save' value='icon-save'></span>");
            sb.AppendLine("<span class='list-span icon-cut' value='icon-cut'></span>");
            sb.AppendLine("<span class='list-span icon-ok' value='icon-ok'></span>");
            sb.AppendLine("<span class='list-span icon-no' value='icon-no'></span>");
            sb.AppendLine("<span class='list-span icon-cancel' value='icon-cancel'></span>");
            sb.AppendLine("<span class='list-span icon-reload' value='icon-reload'></span>");
            sb.AppendLine("<span class='list-span icon-search' value='icon-search'></span>");
            sb.AppendLine("<span class='list-span icon-print' value='icon-print'></span>");
            sb.AppendLine("<span class='list-span icon-undo' value='icon-undo'></span>");
            sb.AppendLine("<span class='list-span icon-redo' value='icon-redo'></span>");
            sb.AppendLine("<span class='list-span icon-back' value='icon-back'></span>");
            sb.AppendLine("<span class='list-span icon-sum' value='icon-sum'></span>");
            sb.AppendLine("<span class='list-span icon-help' value='icon-help'></span>");

            return "<div id='" + id + "' title='选择图标' class='easyui-dialog icon-dialog' data-options='width:492,closed:true,modal:true,iconCls:\"icon-bricks\"'>" + sb.ToString() + "</div>";
        }
    }
}
